<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Proxy</title>
</head>
<body>
  <div id="app">
    hello
  </div>
  <script>
    let data = {
      msg: 'hello',
      count: 0,
      a: {
        b: 123
      }
    }

    let vm = new Proxy(data, {
      get(target, key) {
        console.log('get, key: ', key, target[key])
        return target[key]
      },
      set(target, key, newValue) {
        console.log('set, key: ', key, newValue)
        if(target[key] === newValue) {
          return
        }
        target[key] = newValue
        document.querySelector('#app').textContent = target[key]
      }
    })

    vm.msg = 'hello world';
    console.log(vm.msg)
  </script>
</body>
</html>